package com.xxx.sso.util;

import com.xxx.sso.enums.ErrEnum;
import org.springframework.data.domain.Page;

import java.util.Map;

/**
 * 接口返回值 Builder
 * @author caiwl
 * @date 2020/5/6 10:08
 */
public class ResultBuilder {

    public static Result ok() {
        return Result.builder().code(ErrEnum.OK.getCode()).msg(ErrEnum.OK.getMsg()).build();
    }

    public static Result okWithObj(Object obj) {
        return Result.builder().code(ErrEnum.OK.getCode()).msg(ErrEnum.OK.getMsg()).data(obj).build();
    }

    public static Result okWithMap(Map<String, Object> map) {
        return okWithObj(map);
    }

    public static Result okWithPage(Page page) {
        // TODO 分页字段过多，根据需要删减
        return okWithObj(page);
    }

    public static Result fail() {
        return Result.builder().code(ErrEnum.ERR_SERVER.getCode()).msg(ErrEnum.ERR_SERVER.getMsg()).build();
    }

    public static Result fail(ErrEnum err) {
        return Result.builder().code(err.getCode()).msg(err.getMsg()).build();
    }
}
